home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Entertainment / tblt / tblt⁄finder.c < prev    next >
Encoding:
Text File  |  1986-09-06  |  2.5 KB  |  107 lines  |  [TEXT/MACA]

  1. /*
  2.  * finder.c - finder interface routines for the game of Tablut.
  3.  *
  4.  */
  5.  
  6. #include <quickdraw.h>
  7. #include <window.h>
  8. #include <pb.h>
  9. #include <segment.h>
  10. #include <packages.h>
  11. #include <memory.h>
  12.  
  13. #include "tablut.h"
  14.  
  15. static short dowhat;    /* what the finder says to do        */
  16. static short filecount;    /* the number of files to do it to    */
  17.  
  18. struct launchinfo {    /* stuff for launching another application */
  19.     char *li_name;    /* the name of the file to xfer to    */
  20.     long li_zip;    /* magic...who knows?            */
  21.     short li_code;    /* sound buf & screen magic #...use 0    */
  22. };
  23. static struct launchinfo fireprog;
  24. static char xfername[64];    /* the name of the file to xfer to    */
  25.  
  26. /*
  27.  * quittoprog() - transfer control to a chosen application
  28.  */
  29. quittoprog()
  30. {
  31.     short vnum;        /* volume to launch from    */
  32.  
  33.     if (!(FileFetch(xfername, &vnum, (OSType) 'APPL'))) {
  34.     return;
  35.     }
  36.     fireprog.li_name = xfername;
  37.     fireprog.li_zip = 0;
  38.     fireprog.li_code = 0;
  39.     closeup();
  40.     SetVol((char *) 0, vnum);
  41.     /* do the asm stuff because the Manx 1.06D Launch() was buggy */
  42. #asm
  43.     lea fireprog_, a0
  44.     dc.w    $a9f2
  45. #endasm
  46.     ExitToShell();    /* the launch didn't work, so let's just quit */
  47. }
  48.  
  49. /*
  50.  * bomb() - abort the program.  Most bombs should call progstop() first
  51.  *  to tell the user what went wrong.
  52.  */
  53. bomb()
  54. {
  55.     closeup();  ExitToShell();
  56. }
  57.  
  58. /*
  59.  * seeanyfiles() - read the finder file information to be used by
  60.  *  printanyfiles() and openanyfiles(),
  61.  *  returning TRUE if there are any files to process.
  62.  */
  63. int
  64. seeanyfiles()
  65. {
  66.     CountAppFiles(&dowhat, &filecount);
  67.     return(filecount > 0);
  68. }
  69.  
  70. /*
  71.  * printanyfiles() - a dummy routine that would print files if
  72.  *  Tablut files could be printed.
  73.  */
  74. int    /* 1 == files were to be printed; 0 == no files to print */
  75. printanyfiles()
  76. {
  77.     if (filecount == 0 || dowhat != appPrint) return(0);
  78.     /* Silently ignore finder requests to print files */
  79.     return(1);
  80. }
  81.  
  82. /*
  83.  * openanyfiles() - open any files that were requested from the finder.
  84.  * (actually open only the first file requested.)
  85.  */
  86. int    /* 1 == a file was opened; 0 == none were opened    */
  87. openanyfiles()
  88. {
  89.     AppFile afile;
  90.     int fidx;        /* index of the current finder file    */
  91.  
  92.     if (filecount == 0 || dowhat != appOpen) return(0);
  93.     for (fidx = 1; fidx <= filecount; ++fidx) {
  94.     GetAppFiles(fidx, &afile);
  95.     if (afile.fType != MYFILE) continue;
  96.     movmem((char *) &afile.fName, gamename,
  97.       ((int) afile.fName.length & 0xFF) + 1);
  98.     gamevnum = afile.vRefNum;
  99.     SetWTitle(mywindow, gamename);
  100.     if (!(needsname = !readgamefile())) {
  101.         ClrAppFiles(fidx);
  102.         return(1);
  103.     }
  104.     }
  105.     return(0);
  106. }
  107.